package com.tlvip.arithmetic.ch03;

/**
 * <p>description：双向链表</p>
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary： </p>
 * <p>instructions： </p>
 * Date 1/24/21</p>
 * Author mac
 *
 * @version 1.0
 */
public class DoubleLinkList {
    private DNode head;
    private DNode tail;

    DoubleLinkList() {
        head = null;
        tail = null;
    }

    public void insertHead(int data) {
        DNode newNode = new DNode(data);
        if (head == null) {
            tail = newNode;
        } else {
            // java里面基本都是堆上的引用地址
            head.pre = newNode;
            newNode.next = head;
        }
        head = newNode;
    }

    public void insertNth(int data, int position) {

    }

    public void deleteHead() {
        head.next.pre = null;
        head = head.next;
    }
}

class DNode {
    int value;
    DNode next;
    DNode pre;

    DNode(int value) {
        this.value = value;
        this.next = null;
        this.pre = null;
    }
}